package com.crawler.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Page {
	
	private String mURL;
	private String mContent;
	private String mTitle;
	private boolean mIsRel;
	private Map<String, Integer> mFeatureSet;
	
	private final String DELIMS = "[ .,?;-]+";
	public Page(String URL, String title, String content, List<String> listFeature)
	{
		mURL = URL;
		mTitle = title;
		mContent = content;
		mIsRel = false;
		mFeatureSet = new HashMap<String, Integer>();
		
		ResetFeatureSet(listFeature);
	}
	
	public String GetPageURL()
	{
		return mURL;
	}
	
	public String GetTitle()
	{
		return mTitle;
	}
	
	public String GetContent()
	{
		return mContent;
	}
	
	public void SetRel(boolean bIsRel)
	{
		mIsRel = bIsRel;
	}
	
	public boolean IsRel()
	{
		return mIsRel;
	}
	
	public void ResetFeatureSet(List<String> listFeature)
	{
		mFeatureSet.clear();
		for(String strFeature : listFeature)
		{
			mFeatureSet.put(strFeature, 0);
		}
	}
	
	public void ProcessPage()
	{
		String [] tempArray = mContent.split(DELIMS);
		
		for(String strTemp : tempArray)
		{
			if (mFeatureSet.keySet().contains(strTemp))
			{
				mFeatureSet.put(strTemp, mFeatureSet.get(strTemp)+1);
			}
		}
	}
	
	public Map<String, Integer> GetFeatureSet()
	{
		return mFeatureSet;
	}
	
	public String GetFeatureSetAsString()
	{
		String strRet = "";
		for(Integer value : mFeatureSet.values())
		{
			strRet += value.toString();
			strRet += ",";
		}
		return strRet;
	}
}
